package com.babai.util;

import java.util.Random;

public class RandomUtil {

    private static final char[] charLetters = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
            , 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

    private static final char[] chars = new char[62];

    static {
        int k = 0;
        for (int i = 0; i < charLetters.length; i++, k++) {
            chars[k] = charLetters[i];
        }
        for (int i = 0; i < charLetters.length; i++, k++) {
            chars[k] = Character.toLowerCase(charLetters[i]);
        }
        for (int i = 0; i < 10; i++, k++) {
            chars[k] = String.valueOf(i).toCharArray()[0];
        }
    }

    public static void main(String[] args) {
        //System.out.println(charsOf(6));
    }

    /**
     * 生成{length}长度的随机字符窜
     *
     * @param length
     * @return
     */
    public static String charsOf(int length) {
        int bound = chars.length;
        Random r = new Random();
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int nextInt = r.nextInt(bound);
            buf.append(chars[nextInt]);

        }
        return buf.toString();
    }
}
